const app = getApp();
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    hidden: true,
    fsid:'',
      id:'',
    member:[],
  },
  search1(){
    this.search();
  },
  search(e){
    var that=this;
    console.log(e);
      wx.showLoading({
          mask: true,
          title:'数据加载中...',
      });
    // 搜索所属会员
    wx.request({
      // url: con.index_getread,
      url: 'https://www.brvpmusic.com/certification/findUsersByName/list',
      method: 'GET',
      data: {
        'fsid': that.data.fsid,
        'name': e.detail.value.search,
      },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res.data);
        console.log('返回成功');
        that.setData({
          'member': res.data.body,
        });
        wx.hideLoading();
      },
      fail: function (res) {
        console.log('返回失败');
      }
    })
  },
    getUsersInfo(e){
        console.log("e---"+JSON.stringify(e));
       var cOpenid = e.currentTarget.dataset.copenid;
        var openid = e.currentTarget.dataset.openid;
        console.log("cOpenid---"+cOpenid);
        console.log("openid---"+openid);
        if(typeof(cOpenid)!='undefined'&&typeof(openid)=='undefined'){
            wx.navigateTo({
                url: '/pages/my/personal/personal?openid='+cOpenid,
            });
        }
        if(typeof(openid)!='undefined'&&typeof(cOpenid)=='undefined'){
            wx.navigateTo({
                url: '/pages/my/personal/personal?openid='+openid,
            });
        }
    },
  onLoad(options) {
    var that=this;
    let list = [];
      var params={};
      var url ="";
    for (let i = 0; i < 26; i++) {
      list[i] = String.fromCharCode(65 + i)
    }
    that.setData({
      list: list,
      listCur: list[0]
    });
      wx.showLoading({
          mask: true,
          title:'数据加载中...',
      });
    if (options.fsid!=null){
         params.fsid=options.fsid;
         that.setData({fsid: options.fsid});
         url = 'https://www.brvpmusic.com/certification/getUsers/list'
    } else if(options.id!=null){
            params.id= options.id;
        that.setData({id: options.id});
            url='https://www.brvpmusic.com/api/community/barberHaircutCard'
        // url='http://3s.dkys.org:25333/api/community/barberHaircutCard'
    }
    //获取所属会员
    wx.request({
      // url: con.index_getread,
      url: url,
      method: 'GET',
      data: params,
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res.data);
        console.log('返回成功');
        that.setData({
          'member':res.data.body,
            'list':res.data.body
        });
        wx.hideLoading();
      },
      fail: function (res) {
        console.log('返回失败');
      }
    })
  },
  //获取文字信息
  getCur(e) {
    this.setData({
      hidden: false,
      listCur: this.data.list[e.target.id],
    })
  },

  setCur(e) {
    this.setData({
      hidden: true,
      listCur: this.data.listCur
    })
  },
  //滑动选择Item
  tMove(e) {
    let y = e.touches[0].clientY,
      offsettop = this.data.boxTop,
      that = this;
    //判断选择区域,只有在选择区才会生效
    if (y > offsettop) {
      let num = parseInt((y - offsettop) / 20);
      this.setData({
        listCur: that.data.list[num]
      })
    };
  },

  //触发全部开始选择
  tStart() {
    this.setData({
      hidden: false
    })
  },

  //触发结束选择
  tEnd() {
    this.setData({
      hidden: true,
      listCurID: this.data.listCur
    })
  },
  indexSelect(e) {
    let that = this;
    let barHeight = this.data.barHeight;
    let list = this.data.list;
    let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
    for (let i = 0; i < list.length; i++) {
      if (scrollY < i + 1) {
        that.setData({
          listCur: list[i],
          movableY: i * 20
        })
        return false
      }
    }
  }
});